unit Toolbar;

interface

uses
  Database, AM, Generics.Collections,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ComCtrls, Menus, ExtCtrls;

type
  TFormToolbar = class(TForm)
    List1: TListBox;
    List2: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    BtnAdd: TSpeedButton;
    BtnRemove: TSpeedButton;
    BtnBefore: TSpeedButton;
    BtnAfter: TSpeedButton;
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    BtnUp: TSpeedButton;
    BtnDown: TSpeedButton;
    MainMenu1: TMainMenu;
    MenuMain: TMenuItem;
    MenuUp: TMenuItem;
    MenuDown: TMenuItem;
    BtnHelp: TBitBtn;
    Up21: TMenuItem;
    Down21: TMenuItem;
    BtnSpace: TSpeedButton;
    BtnClear: TBitBtn;
    m1: TSpeedButton;
    m2: TSpeedButton;
    m4: TSpeedButton;
    m3: TSpeedButton;
    m6: TSpeedButton;
    m5: TSpeedButton;
    m7: TSpeedButton;
    m8: TSpeedButton;
    m10: TSpeedButton;
    m9: TSpeedButton;
    m12: TSpeedButton;
    m11: TSpeedButton;
    MenuHelp: TMenuItem;
    E1: TEdit;
    E5: TEdit;
    E9: TEdit;
    E2: TEdit;
    E6: TEdit;
    E10: TEdit;
    E3: TEdit;
    E7: TEdit;
    E11: TEdit;
    Bevel1: TBevel;
    E4: TEdit;
    E8: TEdit;
    E12: TEdit;
    Bevel2: TBevel;
    Label15: TLabel;
    BtnAM: TBitBtn;
    CtrlA1: TMenuItem;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    BitBtn10: TBitBtn;
    BitBtn11: TBitBtn;
    Panel1: TPanel;
    Status: TLabel;
    b1: TSpeedButton;
    b2: TSpeedButton;
    b4: TSpeedButton;
    b3: TSpeedButton;
    b8: TSpeedButton;
    b7: TSpeedButton;
    b6: TSpeedButton;
    b5: TSpeedButton;
    b9: TSpeedButton;
    b11: TSpeedButton;
    b10: TSpeedButton;
    b12: TSpeedButton;
    b13: TSpeedButton;
    b14: TSpeedButton;
    procedure BtnAddClick(Sender: TObject);
    procedure BtnRemoveClick(Sender: TObject);
    procedure BtnBeforeClick(Sender: TObject);
    procedure BtnAfterClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnCancelClick(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure BtnOKClick(Sender: TObject);
    procedure BtnUpClick(Sender: TObject);
    procedure BtnHelpClick(Sender: TObject);
    procedure List1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure List1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure List1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure List1EndDrag(Sender, Target: TObject; X, Y: Integer);
    procedure List1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure BtnClearClick(Sender: TObject);
    procedure m1Click(Sender: TObject);
    procedure BtnAMClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FGlyphDic: TDictionary<string, TBitmap>;
    procedure SetupLists;
    procedure RefreshList1;
    procedure SaveData;
    function FigureBitmap(str: string): TBitmap;
  public
    { Public declarations }
    canceled: boolean;
    procedure Setup;
  end;

var
  FormToolbar: TFormToolbar;
  space: string;

implementation

uses Main;

{$R *.DFM}

{
New Toolbar Button
------------------
FormMain
  HideButtons
  PositionButton

Datawell
  FigureButton
  FigureLetter

FormToolbar
  RefreshList1
  FigureBitmap
}

procedure TFormToolbar.FormCreate(Sender: TObject);
begin
  canceled:=false;
  space:='-----<space>-----';
  FGlyphDic := TDictionary<string, TBitmap>.Create;
   FGlyphDic.add('Exit', FormMain.BtnExit.glyph);
   FGlyphDic.add('Disconnect', FormMain.BtnDisconnect.glyph);
   FGlyphDic.add('Reconnect', FormMain.BtnReconnect.glyph);
   FGlyphDic.add('Lock Character', FormMain.BtnLock.glyph);
   FGlyphDic.add('Panic Button', FormMain.BtnPanic.glyph);
   FGlyphDic.add('Aliases', FormMain.BtnAliases.glyph);
   FGlyphDic.add('Macros', FormMain.BtnMacros.glyph);
   FGlyphDic.add('Quickchars', FormMain.BtnQuickchars.glyph);
   FGlyphDic.add('Events', FormMain.BtnEvents.glyph);
   FGlyphDic.add('Nicknames', FormMain.BtnNicknames.glyph);
   FGlyphDic.add('Ticker', FormMain.BtnTicker.glyph);
   FGlyphDic.add('View System Messages', FormMain.BtnViewFiltered.glyph);
   FGlyphDic.add('Clear System Messages', FormMain.BtnClearFiltered.glyph);
   FGlyphDic.add('Open Autotyper', FormMain.BtnAutotyper.glyph);
   FGlyphDic.add('Autotype', b5.glyph);
   FGlyphDic.add('Copy to Clipboard', FormMain.BtnCopy.glyph);
   FGlyphDic.add('Copy to Autotyper', FormMain.BtnCopyToAutotyper.glyph);
   FGlyphDic.add('Send Text from Clipboard', FormMain.BtnPaste.glyph);
   FGlyphDic.add('Scrollback', FormMain.BtnScrollback.glyph);
   FGlyphDic.add('Escape', FormMain.BtnEscape.glyph);
   FGlyphDic.add('Clear Scrollback', FormMain.BtnClearScrollback.glyph);
   FGlyphDic.add('Clear Keyhistory', FormMain.BtnClearKeyhistory.glyph);
   FGlyphDic.add('Reduce Font', FormMain.BtnReduceFont.glyph);
   FGlyphDic.add('Increase Font', FormMain.BtnIncreaseFont.glyph);
   FGlyphDic.add('Choose Font', FormMain.BtnFont.glyph);
   FGlyphDic.add('Program Options', FormMain.BtnOptions.glyph);
   FGlyphDic.add('Show Tell Monitor', FormMain.BtnTell.glyph);
   FGlyphDic.add('Show Imagery', FormMain.BtnImagery.glyph);
   FGlyphDic.add('Customize Toolbar', FormMain.BtnToolbar.glyph);
   FGlyphDic.add('Capture Scrollback to File', FormMain.BtnCapture.glyph);
   FGlyphDic.add('Help', FormMain.BtnHelp.glyph);
   FGlyphDic.add('Setup Display Colors', FormMain.BtnDisplay.glyph);
   FGlyphDic.add('Setup Groups', FormMain.BtnGroups.glyph);
   FGlyphDic.add('Show Chat Monitor', FormMain.BtnChat.glyph);
   FGlyphDic.add('Log Incoming Text to File', FormMain.BtnLog.glyph);
   FGlyphDic.add('Activate the BASE Group', FormMain.BtnBASE.glyph);
   FGlyphDic.add('Find Text', FormMain.BtnFind.glyph);
   FGlyphDic.add('Find Next', FormMain.BtnNext.glyph);
   FGlyphDic.add('Find Previous', FormMain.BtnPrior.glyph);
   FGlyphDic.add('Jumpstart Portal', FormMain.BtnJumpstart.glyph);
   FGlyphDic.add('Custom Button 1', FormMain.m1.glyph);
   FGlyphDic.add('Custom Button 2', FormMain.m2.glyph);
   FGlyphDic.add('Custom Button 3', FormMain.m3.glyph);
   FGlyphDic.add('Custom Button 4', FormMain.m4.glyph);
   FGlyphDic.add('Custom Button 5', FormMain.m5.glyph);
   FGlyphDic.add('Custom Button 6', FormMain.m6.glyph);
   FGlyphDic.add('Custom Button 7', FormMain.m7.glyph);
   FGlyphDic.add('Custom Button 8', FormMain.m8.glyph);
   FGlyphDic.add('Custom Button 9', FormMain.m9.glyph);
   FGlyphDic.add('Custom Button 10', FormMain.m10.glyph);
   FGlyphDic.add('Custom Button 11', FormMain.m11.glyph);
   FGlyphDic.add('Custom Button 12', FormMain.m12.glyph);
   FGlyphDic.add('Copy Download to Autotyper', b1.glyph);
   FGlyphDic.add('Capture Download to File', b3.glyph);
   FGlyphDic.add('Clear Download', b4.glyph);
   FGlyphDic.add('Paste Download into Autotyper', b2.glyph);
   FGlyphDic.add('Upload Files', FormMain.BtnUpload.glyph);
   FGlyphDic.add('Graph Paper Generator', FormMain.BtnMapper.glyph);
   FGlyphDic.add('Variables', FormMain.BtnVars.glyph);
   FGlyphDic.add('Cartographer', FormMain.BtnMap.glyph);
   FGlyphDic.add('Quick Event', FormMain.BtnQuickEvent.glyph);
   FGlyphDic.add('Music Play', b6.glyph);
   FGlyphDic.add('Music Pause', b7.glyph);
   FGlyphDic.add('Music Rewind', b8.glyph);
   FGlyphDic.add('Music Playlist Editor', b9.glyph);
   FGlyphDic.add('Load Music Playlist', b12.glyph);
   FGlyphDic.add('Music Previous', b10.glyph);
   FGlyphDic.add('Music Next', b11.glyph);
   FGlyphDic.add('Music First', b13.glyph);
   FGlyphDic.add('Music Last', b14.glyph);
   FGlyphDic.add('Canvas', FormMain.BtnCanvas.glyph);
   FGlyphDic.add('Attempt Secondary Connection', FormMain.BtnSecondary.glyph);
   FGlyphDic.add('Disconnect Secondary Connection', FormMain.BtnSecondaryDisconnect.glyph);
   FGlyphDic.add('Reverse Connection Control', FormMain.BtnSecondaryReverse.glyph);
   FGlyphDic.add('Customize Menu Hotkeys', FormMain.BtnHotkeys.glyph);
   FGlyphDic.add('Import/Export', FormMain.BtnIO.glyph);
   FGlyphDic.add('Autoscribble', FormMain.BtnAutoscribble.glyph);
   FGlyphDic.add('Send Text File', FormMain.BtnSendTextFile.glyph);;
end;

procedure TFormToolbar.FormDestroy(Sender: TObject);
begin
  FGlyphDic.Free;
end;

procedure TFormToolbar.Setup;
begin
  RefreshList1;
  SetupLists;
  E1.text:=Datawell.TableOptions3.fieldbyname('Tool1').asstring;
  E2.text:=Datawell.TableOptions3.fieldbyname('Tool2').asstring;
  E3.text:=Datawell.TableOptions3.fieldbyname('Tool3').asstring;
  E4.text:=Datawell.TableOptions3.fieldbyname('Tool4').asstring;
  E5.text:=Datawell.TableOptions3.fieldbyname('Tool5').asstring;
  E6.text:=Datawell.TableOptions3.fieldbyname('Tool6').asstring;
  E7.text:=Datawell.TableOptions3.fieldbyname('Tool7').asstring;
  E8.text:=Datawell.TableOptions3.fieldbyname('Tool8').asstring;
  E9.text:=Datawell.TableOptions3.fieldbyname('Tool9').asstring;
  E10.text:=Datawell.TableOptions3.fieldbyname('Tool10').asstring;
  E11.text:=Datawell.TableOptions3.fieldbyname('Tool11').asstring;
  E12.text:=Datawell.TableOptions3.fieldbyname('Tool12').asstring;
end;

procedure TFormToolbar.BtnAddClick(Sender: TObject);
begin
  if List2.items.count >= 250 then exit;
  if List1.itemindex < 0 then exit;
  if List2.itemindex >=0 then begin
    List2.items.insert(List2.itemindex,List1.items[List1.itemindex]);
  end
  else List2.items.add(List1.items[List1.itemindex]);
  List1.items.delete(List1.itemindex);
end;

procedure TFormToolbar.BtnRemoveClick(Sender: TObject);
begin
  if List2.itemindex < 0 then exit;
  if List2.items[List2.itemindex] <> space then
    List1.items.add(List2.items[List2.itemindex]);
  List2.items.delete(List2.itemindex);
  RefreshList1;
end;

procedure TFormToolbar.BtnBeforeClick(Sender: TObject);
begin
  if List2.items.count >= 250 then exit;
  if List2.itemindex < 0 then exit;
  List2.items.insert(List2.itemindex,space)
end;

procedure TFormToolbar.BtnAfterClick(Sender: TObject);
begin
  if List2.items.count >= 250 then exit;
  if List2.itemindex < 0 then exit;
  if List2.itemindex = List2.items.count-1 then
    List2.items.add(space)
  else List2.items.insert(List2.itemindex+1,space)
end;

procedure TFormToolbar.SetupLists;
var
  data: string;
  i: integer;
begin
  data:=Datawell.TableOptions.fieldbyname('Toolbar').asstring;
  while length(data) > 0 do begin
    if data[1] = '_' then List2.items.add(space)
    else begin
      i:=List1.items.indexof(Datawell.FigureButton(data[1]));
      if i >= 0 then begin
        List2.items.add(List1.items[i]);
        List1.items.delete(i);
      end;
    end;
    delete(data,1,1);
  end;
end;

procedure TFormToolbar.RefreshList1;
var i, j: integer;
begin
  List1.items.clear;
  List1.items.add('Escape');
  List1.items.add('Panic Button');
  List1.items.add('Jumpstart Portal');
  List1.items.add('Lock Character');
  List1.items.add('Clear Keyhistory');
  List1.items.add('Graph Paper Generator');
  List1.items.add('Copy Download to Autotyper');
  List1.items.add('Paste Download into Autotyper');
  List1.items.add('Capture Download to File');
  List1.items.add('Clear Download');
  List1.items.add('Upload Files');
  List1.items.add('Disconnect');
  List1.items.add('Reconnect');
  List1.items.add('Attempt Secondary Connection');
  List1.items.add('Disconnect Secondary Connection');
  List1.items.add('Reverse Connection Control');
  List1.items.add('Import/Export');
  List1.items.add('Exit');
  List1.items.add('Copy to Clipboard');
  List1.items.add('Copy to Autotyper');
  List1.items.add('Send Text from Clipboard');
  List1.items.add('Send Text File');
  List1.items.add('Scrollback');
  List1.items.add('Find Text');
  List1.items.add('Find Next');
  List1.items.add('Clear Scrollback');
  List1.items.add('Capture Scrollback to File');
  List1.items.add('Log Incoming Text to File');
  List1.items.add('Aliases');
  List1.items.add('Macros');
  List1.items.add('Quickchars');
  List1.items.add('Nicknames');
  List1.items.add('Ticker');
  List1.items.add('Events');
  List1.items.add('Quick Event');
  List1.items.add('Variables');
  List1.items.add('Setup Groups');
  List1.items.add('Activate the BASE Group');
  List1.items.add('Open Autotyper');
  List1.items.add('Autotype');
  List1.items.add('Autoscribble');
  List1.items.add('Program Options');
  List1.items.add('Music Playlist Editor');
  List1.items.add('Load Music Playlist');
  List1.items.add('Music Play');
  List1.items.add('Music Pause');
  List1.items.add('Music Rewind');
  List1.items.add('Music Previous');
  List1.items.add('Music Next');
  List1.items.add('Music First');
  List1.items.add('Music Last');
  List1.items.add('Customize Toolbar');
  List1.items.add('Customize Menu Hotkeys');
  List1.items.add('Reduce Font');
  List1.items.add('Increase Font');
  List1.items.add('Choose Font');
  List1.items.add('Setup Display Colors');
  List1.items.add('Canvas');
  List1.items.add('Show Imagery');
  List1.items.add('Show Chat Monitor');
  List1.items.add('Show Tell Monitor');
  List1.items.add('Cartographer');
  List1.items.add('View System Messages');
  List1.items.add('Clear System Messages');
  List1.items.add('Help');
  List1.items.add('Custom Button 1');
  List1.items.add('Custom Button 2');
  List1.items.add('Custom Button 3');
  List1.items.add('Custom Button 4');
  List1.items.add('Custom Button 5');
  List1.items.add('Custom Button 6');
  List1.items.add('Custom Button 7');
  List1.items.add('Custom Button 8');
  List1.items.add('Custom Button 9');
  List1.items.add('Custom Button 10');
  List1.items.add('Custom Button 11');
  List1.items.add('Custom Button 12');
  if List2.items.count < 1 then exit;
  for i:=0 to List2.items.count-1 do begin
    j:=List1.items.indexof(List2.items[i]);
    if j >= 0 then List1.items.delete(j);
  end;
end;

procedure TFormToolbar.SaveData;
var
  data: string;
  i: integer;
begin
  data:='';
  for i:=0 to List2.items.count-1 do begin
    if List2.items[i] = space then data:=data+'_'
    else data:=data+Datawell.FigureLetter(List2.items[i]);
  end;
  Datawell.TableOptions.edit;
  Datawell.TableOptions.fieldbyname('Toolbar').asstring:=data;
  Datawell.TableOptions.post;
  Datawell.TableOptions3.edit;
  Datawell.TableOptions3.fieldbyname('Tool1').asstring:=E1.text;
  Datawell.TableOptions3.fieldbyname('Tool2').asstring:=E2.text;
  Datawell.TableOptions3.fieldbyname('Tool3').asstring:=E3.text;
  Datawell.TableOptions3.fieldbyname('Tool4').asstring:=E4.text;
  Datawell.TableOptions3.fieldbyname('Tool5').asstring:=E5.text;
  Datawell.TableOptions3.fieldbyname('Tool6').asstring:=E6.text;
  Datawell.TableOptions3.fieldbyname('Tool7').asstring:=E7.text;
  Datawell.TableOptions3.fieldbyname('Tool8').asstring:=E8.text;
  Datawell.TableOptions3.fieldbyname('Tool9').asstring:=E9.text;
  Datawell.TableOptions3.fieldbyname('Tool10').asstring:=E10.text;
  Datawell.TableOptions3.fieldbyname('Tool11').asstring:=E11.text;
  Datawell.TableOptions3.fieldbyname('Tool12').asstring:=E12.text;
  Datawell.TableOptions3.post;
end;

procedure TFormToolbar.BtnCancelClick(Sender: TObject);
begin
  canceled:=true;
  close;
end;

procedure TFormToolbar.FormMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  Status.caption:=' '+(sender as TControl).hint;
end;

procedure TFormToolbar.BtnOKClick(Sender: TObject);
begin
  SaveData;
  close;
end;

procedure TFormToolbar.BtnUpClick(Sender: TObject);
var
  arg, i: integer;
  h: string;
begin
  arg:=(sender as TComponent).tag;
  i:=List2.itemindex;
  if i < 0 then exit;
  if (i = 0) and (arg < 0) then exit;
  if (i = (List2.items.count-1)) and (arg > 0) then exit;
  h:=List2.items[i+arg];
  List2.items[i+arg]:=List2.items[i];
  List2.items[i]:=h;
  List2.itemindex:=i+arg;
end;

procedure TFormToolbar.BtnHelpClick(Sender: TObject);
begin
  Datawell.Help('customize_toolbar');
end;

procedure TFormToolbar.List1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then with (sender as TListBox) do begin
    if ItemAtPos(Point(x,y),True) >= 0 then BeginDrag(False);
  end;
end;

procedure TFormToolbar.List1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  if Source is TListBox then Accept:=true;
end;

procedure TFormToolbar.List1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var Holder, Counter_1: integer;
begin
  with (source as TListBox) do begin
    Holder:=items.count;
    for Counter_1:=0 to Holder-1 do begin
      if Selected[Counter_1] then begin
        TListBox(Sender).items.add(items[Counter_1]);
      end;
    end;
  end;
end;

procedure TFormToolbar.List1EndDrag(Sender, Target: TObject; X,
  Y: Integer);
var
  Counter_1: integer;
  done: boolean;
begin
  if Target <> nil then begin
    done:=false;
    Counter_1:=0;
    while not done do begin
      if TListBox(sender).selected[Counter_1] then TListBox(sender).items.delete(Counter_1);
        if (Counter_1+1) <= TListBox(sender).items.count then
          if not TListBox(sender).selected[Counter_1] then
            Counter_1:=Counter_1+1;
        if Counter_1 >= TListBox(sender).items.count then done:=true;
    end;
    RefreshList1;
  end;
end;

function TFormToolbar.FigureBitmap(str: string): TBitmap;
begin
  if not FGlyphDic.TryGetValue(str, result) then
    result:=BtnSpace.glyph;
end;

procedure TFormToolbar.List1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var bitmap: TBitmap;
begin  with (control as TListBox).canvas do	begin    FillRect(Rect);    bitmap:=FigureBitmap((control as TListBox).items[index]);    if Bitmap <> nil then begin      BrushCopy(Bounds(Rect.left+2,Rect.top,bitmap.width,bitmap.height),bitmap,        Bounds(0,0,Bitmap.width,Bitmap.height),clsilver);
    end;
    TextOut(Rect.left+18,Rect.top,(control as TListBox).items[Index])  end;end;

procedure TFormToolbar.BtnClearClick(Sender: TObject);
var
  data: string;
  i: integer;
begin
  List2.items.clear;
  RefreshList1;
  data:='a_4bc_defh_g>-_Y_kl_s_w';
  while length(data) > 0 do begin
    if data[1] = '_' then List2.items.add(space)
    else begin
      i:=List1.items.indexof(Datawell.FigureButton(data[1]));
      List2.items.add(List1.items[i]);
      List1.items.delete(i);
    end;
    delete(data,1,1);
  end;
end;

procedure TFormToolbar.m1Click(Sender: TObject);
var ed: TEdit;
begin
  case TComponent(sender).tag of
    1: ed:=E1;
    2: ed:=E2;
    3: ed:=E3;
    4: ed:=E4;
    5: ed:=E5;
    6: ed:=E6;
    7: ed:=E7;
    8: ed:=E8;
    9: ed:=E9;
   10: ed:=E10;
   11: ed:=E11;
   12: ed:=E12;
    else raise Exception.CreateFmt('TFormToolbar.m1Click: Invalid sender tag: %d', [TComponent(sender).tag]);
  end;
  ed.selectall;
  ed.setfocus;
end;

procedure TFormToolbar.BtnAMClick(Sender: TObject);
var
  form: TFormAM;
  am: string;
  ed: TEdit;
begin
  if (TComponent(sender).tag = 999) then begin
    if ActiveControl = E1 then ed:=E1
    else if ActiveControl = E2 then ed:=E2
    else if ActiveControl = E3 then ed:=E3
    else if ActiveControl = E4 then ed:=E4
    else if ActiveControl = E5 then ed:=E5
    else if ActiveControl = E6 then ed:=E6
    else if ActiveControl = E7 then ed:=E7
    else if ActiveControl = E8 then ed:=E8
    else if ActiveControl = E9 then ed:=E9
    else if ActiveControl = E10 then ed:=E10
    else if ActiveControl = E11 then ed:=E11
    else if ActiveControl = E12 then ed:=E12
    else exit;
  end
  else begin
    case TComponent(sender).tag of
      1: ed:=E1;
      2: ed:=E2;
      3: ed:=E3;
      4: ed:=E4;
      5: ed:=E5;
      6: ed:=E6;
      7: ed:=E7;
      8: ed:=E8;
      9: ed:=E9;
      10: ed:=E10;
      11: ed:=E11;
      12: ed:=E12;
      else raise Exception.CreateFmt('TFormToolbar.BtnAMClick: Invalid sender tag: %d', [TComponent(sender).tag]);
    end;
  end;
  form:=TFormAM.create(self);
  form.setup;
  form.showmodal;
  am:=form.am;
  form.free;
  if am = '' then exit;
  ed.text:=am;
  ed.setfocus;
end;

end.





